package presentation;

import java.awt.GridLayout;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JPanel;

import org.jfree.chart.ChartPanel;

import entity.ERegister;

public class PSmallGraphPanel extends JPanel implements Observer {
	private static final long serialVersionUID = 1L;
	private ChartPanel speedGraph, rpmGraph;

	public PSmallGraphPanel(ChartPanel speedGraph, ChartPanel rpmGraph) {
		this.speedGraph = speedGraph;
		this.rpmGraph = rpmGraph;
		this.setLayout(new GridLayout(2,1,0,0));
		this.add(speedGraph);
		this.add(rpmGraph);
	}
	
	@Override
	public void update(Observable obs, Object arg) {
		if (arg instanceof Number && obs instanceof ERegister) {
			if (((ERegister) obs).getName().equalsIgnoreCase("RPM")) {
				PChartFactory.addSample(rpmGraph.getChart(), (Number) arg);
			} else if (((ERegister) obs).getName().equalsIgnoreCase("FSSpeed")) {
				PChartFactory.addSample(speedGraph.getChart(), (Number) arg);
			}
		}
	}
}
